<?php
namespace Admin\Controller;
class AccessController extends BaceController {
/* 
 *添加权限 
 *  
 */
    public function access_add() {
        if (!empty($_POST)) {
            $access=$_POST['access'];
            $Url=$_POST['Url'];
            if (mb_strlen($access)<1 || mb_strlen($access)>15) {
                $this->ajaxReturn(array('pass'=>1,'msg'=>'请输入合法的权限标题！'));
            }
            if (mb_strlen($Url)<5) {
                $this->ajaxReturn(array('pass'=>1,'msg'=>'请输入合法的Urls!'));
            }
            //执行添加操作
            $accessOb=M('Access');
            $updated_time=date('Y-m-d H:i:s',time());
            $url_json=json_encode($Url);
            $data=array(
               'updated_time'=>$updated_time,
                'title'=>$access,
                'urls'=>$url_json,
            );
            $re=$accessOb->data($data)->add();
            if ($re) {
                $this->ajaxReturn(array('pass'=>1,'msg'=>'添加成功 ！'));
            }
        }
        $this->display();
    }
    //权限列表
   public function access_list() {

        $accessOb=M('Access');
        $arr=$accessOb->where('status=1')
                 ->select();
        $this->assign('arr',$arr);
        $this->display();
    }
    //修改
    public function access_save() {
        if ($_GET) {
            $id=$_GET['id'];
            $this->assign('id',$id);
            $urls=$_GET['urls'];
            $this->assign('urls',$urls);
            $title=$_GET['title'];
            $this->assign('title',$title);
        }
        if ($_POST) {
            $title=$_POST['title'];
            $url=$_POST['url'];
            $urls=json_encode($url);
            $id=$_POST['id'];
            $data=array(
              'title'=>$title,
               'urls'=>$urls
            );
           $re= M('Access')->where("id=$id")->data($data)->save();
             if ($re) {
                 $this->ajaxReturn(array('pass'=>1,'msg'=>'操作成功！'));
             }
        }
        $this->display();
    }
    //删除
    public function access_delete() {
        $id=$_POST['id'];
        $re=M('access')->where("id=$id")->delete();
        if ($re) {
            $this->ajaxReturn(array('pass'=>1));
        }
    }
}